# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=ospd-openvas
pkgver=22.7.1
pkgrel=0
pkgdesc="ospd-openvas is an OSP server implementation to allow GVM to remotely control an OpenVAS Scanner"
url="https://github.com/greenbone/ospd-openvas"
arch="noarch"
license="AGPL-3.0-or-later"
pkgusers="gvm"
pkggroups="gvm"
depends="
	py3-defusedxml
	py3-deprecated
	py3-gnupg
	py3-lxml
	py3-packaging
	py3-paho-mqtt
	py3-psutil
	py3-redis
	mosquitto
	"
makedepends="py3-gpep517 py3-installer py3-poetry-core"
checkdepends="py3-pytest py3-gnupg"
subpackages="$pkgname-openrc $pkgname-pyc"
install="$pkgname.post-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/greenbone/ospd-openvas/archive/v$pkgver.tar.gz
	$pkgname.initd
	ospd.conf
	fix-test-unlink.patch
	"
# !fhs: /run/ospd referenced in /etc/openvas/ospd.conf
options="!fhs"

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	if [ $arch = "x86" ]; then
		pytest --deselect tests/messaging/test_mqtt.py::MQTTDaemonTestCase
	else
		python3 -m venv --clear --without-pip --system-site-packages .testenv
		.testenv/bin/python3 -m installer .dist/*.whl
		.testenv/bin/python3 -m pytest
	fi
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
	install -d -o $pkgusers -g $pkggroups "$pkgdir"/run/ospd
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/ospd.conf "$pkgdir"/etc/openvas/ospd.conf
}

sha512sums="
ae7fe56a2b825efc33d9e29f2a51ab1034155ee70a5790d98f3b811a29f4b35830afabc27abd14593d74e1bcc5dac0ea1cd33ed46cc3ca459256a4b452e10552  ospd-openvas-22.7.1.tar.gz
264aa78a9909011de6800cf2839d2729bde4c2a8689d7a550c573d2d489c39dc224d7dc52d59210518aa1e2a9ae6a94beac978126f573bd87f378b6fa57511cf  ospd-openvas.initd
2f571f41b34599cc0fb772203f69c781f9c6b043d1451fbd0f930d8040a6888dd832578ac8afdba3015db926b51c7ada56dd435e72f9fa4fffb99d2e769d74aa  ospd.conf
d266ad2cfdcf869cdbe8cfd06a0fa354e583cc2dfa4c3aaf2b478b5af3524a2a39d53ae08ac4816881bbca264262258ed08d077dc0e5a344a9ad091cbc1a656e  fix-test-unlink.patch
"
